Skip to content

Prevent glibc dlopen leak at thread exit#128

Merged
nmoinvaz merged 1 commit intomasterfrom
nathan/pthread-leak
Mar 19, 2026
Merged

Prevent glibc dlopen leak at thread exit#128
nmoinvaz merged 1 commit intomasterfrom
nathan/pthread-leak

Conversation

@nmoinvaz
Copy link
Copy Markdown
Collaborator

@nmoinvaz nmoinvaz commented Mar 19, 2026

Returning NULL from the thread function is equivalent to pthread_exit(NULL) but avoids the glibc unwind link path that allocates memory via dlopen which is never freed.

@nmoinvaz nmoinvaz added the bug Something isn't working label Mar 19, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the pthread-based threadpool worker thread exit path to return from the thread start routine instead of calling pthread_exit(NULL), aligning with the goal of avoiding a glibc thread-exit unwind path that can allocate via dlopen and not free that memory.

Changes:

  • Replaced pthread_exit(NULL) with return NULL; in threadpool_do_work.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.83%. Comparing base (df114f1) to head (6569bde).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #128      +/-   ##
==========================================
+ Coverage   58.57%   63.83%   +5.26%     
==========================================
  Files          32       34       +2     
  Lines        2607     2912     +305     
  Branches      526      546      +20     
==========================================
+ Hits         1527     1859     +332     
+ Misses        745      707      -38     
- Partials      335      346      +11     
Flag Coverage Δ
macos 60.91% <100.00%> (+5.84%) ⬆️
macos_duktape 66.08% <100.00%> (+6.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nmoinvaz nmoinvaz enabled auto-merge (rebase) March 19, 2026 18:18
@nmoinvaz nmoinvaz changed the title Avoid pthread_exit to prevent glibc dlopen leak at thread exit Prevent glibc dlopen leak at thread exit Mar 19, 2026
Returning NULL from the thread function is equivalent to
pthread_exit(NULL) but avoids the glibc unwind link path that allocates
memory via dlopen which is never freed.
@nmoinvaz nmoinvaz force-pushed the nathan/pthread-leak branch from ecb609a to 6569bde Compare March 19, 2026 18:25
@nmoinvaz nmoinvaz requested a review from sergio-nsk March 19, 2026 18:38
@nmoinvaz
Copy link
Copy Markdown
Collaborator Author

Bump.

@nmoinvaz nmoinvaz merged commit 2bd7289 into master Mar 19, 2026
15 checks passed
@nmoinvaz nmoinvaz deleted the nathan/pthread-leak branch March 19, 2026 20:19
@sergio-nsk
Copy link
Copy Markdown
Collaborator

FYI. This was not a real leak. It was re-used by next pthread_create and freed when the main thread exits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants